﻿/// <reference path="../jquery/jquery-1.6.2-vsdoc.js" />

$().ready(function () {
    $("#demo").accordion()
                        .css("width", "75%")
                        .css("margin-left", "100px");
    $("h3").css("color", "Green");
    $initVal();
    $("#dialog-form").dialog({
        autoOpen: false,
        modal: true,
        buttons: {
            保存: function () {
                $getVal();
            }
        }
    });
    $("#mails").click(function () {
        $("#dialog-form").dialog("open");
    })
})

$getVal = function () {
    var str = "";
    $("#dialog-form input:checked").each(function () {
        str += $(this).val() + ",";
    })
    str = str.substr(0, str.lastIndexOf(","));
    $("#mails").val(str);
    $("#dialog-form").dialog("close");
};

$initVal = function () {
    var _val = $("#mails").val();
    var arr = _val.split(",");
    $("#dialog-form input[type=checkbox]").each(function () {
        for (var i = 0; i < arr.length; i++) {
            if ($(this).val() == arr[i]) {
                $(this).attr("checked", true);
            }
        }
    });
}